package com.example.lock;

import org.junit.Test;

/**
 * @author csp 2020-12-21
 */
public class LockTest {
    //    private static AtomicInteger count = new AtomicInteger(0);
    private static Integer count = 0;
    @Test
    public void test() throws InterruptedException {
        for (int i = 0; i < 2; i++) {
            new Thread(()->{
                try {
                    Thread.sleep(10);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                //每个线程让count自增100次
                for (int j = 0; j < 100; j++) {
                    synchronized (this){
                        count++;
                    }
                }
            }).start();
        }
        Thread.sleep(2000);
        System.out.println(count);
    }
}
